﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmsUI.N77;

namespace DogManager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnRead_Click(object sender, EventArgs e)
        {
            CheckDog.Clear();
            cbDtgs800.Checked = false;
            cbGsm.Checked = false;
            cbCDMA.Checked = false;
            tbPortNum.Text = "0";
            if (CheckDog.CheckDog2() < 0)
            {
                MessageBox.Show("没有找到加密狗,请确认已用原厂工具生产过。");
            }
            else
            {
                foreach (int i in CheckDog.SpMaType)
                {
                    if (i == 0)
                    {
                        cbDtgs800.Checked = true;
                    }
                    if (i == 1)
                    {
                        cbGsm.Checked = true;
                    }
                    if (i == 2)
                    {
                        cbCDMA.Checked = true;
                    }
                }
                tbPortNum.Text = CheckDog.PortCount.ToString();
            }
        }

        private void btnWrite_Click(object sender, EventArgs e)
        {
            CheckDog.Clear();
            if (cbDtgs800.Checked)
            {
                CheckDog.SpMaType.Add(0);
            }
            if (cbGsm.Checked)
            {
                CheckDog.SpMaType.Add(1);
            }
            if (cbCDMA.Checked)
            {
                CheckDog.SpMaType.Add(2);
            }
            int count = 0;
            try
            {
                count = int.Parse(tbPortNum.Text);
            }
            catch
            {
                MessageBox.Show("数量输入错误!");
                return;
            }
            CheckDog.PortCount = count;
            CheckDog.CheckDog2Write();
        }
    }
}
